/**
 * 
 */
package com.tvshows.front.controllers.favorite;

import com.tvshows.front.controllers.FrontController;
import com.tvshows.front.factory.TypeUI;
import com.tvshows.front.factory.ViewFactory;
import com.tvshows.front.ui.favorite.FavoriteUI;
import com.tvshows.front.ui.favorite.ListCompositeFavoriteUI;
import com.tvshows.front.ui.favorite.UpsideCompositeFavoriteUI;
import com.tvshows.interactions.ObserverBdd;
import com.tvshows.structure.bdd.BddQueries;

/**
 * @author tMidy
 * <p>
 * Controller of the {@link FavoriteUI}
 * </p>
 */
public class FavoriteController
    implements FrontController
{




    /**
     * favorite view
     */
    private final FavoriteUI favoriteView;

    /**
     * List Composite FavoriteView
     */
    private final ListCompositeFavoriteUI listCompositeFavoriteView;

    /**
     * Upside Composite favorite view
     */
    private UpsideCompositeFavoriteUI upsideComposietFavoriteView;

    /**
     * Constructeur
     */
    public FavoriteController()
    {
        favoriteView = (FavoriteUI) ViewFactory.getUI( TypeUI.FAVORITE_VIEW );
        listCompositeFavoriteView = favoriteView.getListCompositeFavoriteUI();
        upsideComposietFavoriteView = favoriteView.getUpsideCompositeFavoriteUI();
        ObserverBdd.getObserverBdd().setListFavorite( this );
    }

    /**
     * @return favoriteView
     */
    public FavoriteUI getFavoriteView()
    {
        return favoriteView;
    }

    /**
     * @return {@link ListCompositeFavoriteUI}
     */
    public ListCompositeFavoriteUI getListCompositeFavoriteView()
    {
        return listCompositeFavoriteView;
    }

    /**
     * @return the upsideComposietFavoriteView
     */
    public UpsideCompositeFavoriteUI getUpsideComposietFavoriteView()
    {
        return upsideComposietFavoriteView;
    }

    /**
     * @param upsideComposietFavoriteView the upsideComposietFavoriteView to set
     */
    public void setUpsideComposietFavoriteView( UpsideCompositeFavoriteUI upsideComposietFavoriteView )
    {
        this.upsideComposietFavoriteView = upsideComposietFavoriteView;
    }

    /**
     * @see com.tvshows.front.controllers.FrontController#initFormData()
     */
    @Override
    public void initFormData()
    {
        favoriteView.initFormData();
    }

    /**
     * @see com.tvshows.front.controllers.FrontController#initComposites()
     */
    @Override
    public void initComposites()
    {
        favoriteView.initComposites();
        listCompositeFavoriteView.setController( this );
    }

    /**
     * Loads the favorite shows
     */
    public void loadFavorites()
    {
        listCompositeFavoriteView.loadFavorites( BddQueries.getBddQueries().loadFavorites() );
    }

    /**
     * Active deletes on favorites
     */
    public void activeDeleteOnFavorite()
    {
        listCompositeFavoriteView.majDelete();
    }

    /**
     * @param delete enables delete button
     */
    public void enableDelete( boolean delete )
    {
        upsideComposietFavoriteView.enableDelete( delete );
    }

    /**
     * @return the selected favorite
     */
    public String getSelectedFavorite()
    {
        return listCompositeFavoriteView.getSelectedFavorite();
    }

    /**
     * @return true if modifying
     */
    public boolean isToModify()
    {
        return listCompositeFavoriteView.isToModify();
    }

}
